/*
** loop.c for philosophes in /home/cedric/work/cunix/epi-philosophes
** 
** Made by Cedric
** Login   <cedric@epitech.net>
** 
** Started on  Wed May  4 17:56:37 2011 Cedric
** Last update Wed May  4 18:06:18 2011 Cedric
*/

# define  _XOPEN_SOURCE  (500)

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include "philo.h"
#include "actions.h"
#include "xpthreads.h"

void		loop(t_philo *philo)
{
  t_philo	*head;
  pthread_t	thread;

  head = philo;
  while (42)
    {
      while (philo)
	{
	  if (philo->d == plein && philo->g == plein)
	    xpthread_create(&thread, NULL, &mange, philo);
	  else if (philo->d == vide && philo->g == vide) 
	    xpthread_create(&thread, NULL, &repos, philo);
	  else
	    xpthread_create(&thread, NULL, &pense, philo);
	  xpthread_join(thread, NULL);
	  philo = philo->next;
	}
      philo = head;
      while (philo && (philo->g != plein && philo->d != plein))
	philo = check_next(philo);
      donne(philo, 1);
      sleep(5);
      xwrite(1, "-----------------------------\n", 30);
      philo = head;
    }
}

